package com.cgnpc.scp.run.controller;

import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.framework.utils.HttpServlet;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.run.mybatis.entity.*;
import com.cgnpc.scp.run.pojo.ProjectImplementVo;
import com.cgnpc.scp.run.service.ProjectImplementationService;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.List;

/**********************************
 * 用途说明: 项目实施界面控制器
 * 作者姓名: zhangyibing
 * 创建时间: 2020年9月14日17:09:41
 ***********************************/
@RestController
@RequestMapping("/run/projectImplementation")
public class ProjectImplementationController {
    private static final Logger LOGGER = LoggerFactory.getLogger(MarketInfoController.class);

    @Autowired
    private ProjectImplementationService projectImplementationService;

    @Autowired
    private MessageSource messageSource;

    /**********************************
     * 用途说明: 项目实施 - 组建项目实施团队
     * 参数说明 projectImplementation 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="组建项目承揽团队")
    @UBA(module = "调试经营管理", action = "组建项目承揽团队", channel = OperatorType.Button)
    @RequestMapping(value = "/team", method = {RequestMethod.POST})
    public AjaxResult team(HttpServletRequest request, @RequestBody ProjectImplementationTeam projectImplementationTeam){
        try {
            return projectImplementationService.team(projectImplementationTeam);
        } catch (Exception e) {
            LOGGER.error("ProjectImplementationController team error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 项目实施 - 项目属性认定
     * 参数说明 ProjectImplementationShuxing 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="项目实施 - 项目属性认定")
    @UBA(module = "调试经营管理", action = "项目属性认定", channel = OperatorType.Button)
    @RequestMapping(value = "/option", method = {RequestMethod.POST})
    public AjaxResult option(HttpServletRequest request, @RequestBody ProjectImplementationShuxing projectImplementationShuxing){
        try {
            return projectImplementationService.option(projectImplementationShuxing);
        } catch (Exception e) {
            LOGGER.error("ProjectImplementationController option error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 项目实施 - wbs及预算申请
     * 参数说明 ProjectImplementationWbs 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="项目实施 - wbs及预算申请")
    @UBA(module = "调试经营管理", action = "WBS及预算申请", channel = OperatorType.Button)
    @RequestMapping(value = "/wbs", method = {RequestMethod.POST})
    public AjaxResult wbs(HttpServletRequest request, @RequestBody ProjectImplementationWbs projectImplementationWbs){
        try {
            return projectImplementationService.wbs(projectImplementationWbs);
        } catch (Exception e) {
            LOGGER.error("ProjectImplementationController wbs error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 项目实施 - 项目总结
     * 参数说明 ProjectImplementationSummary 实体
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="项目实施 - 项目总结")
    @UBA(module = "调试经营管理", action = "项目总结", channel = OperatorType.Button)
    @RequestMapping(value = "/summary", method = {RequestMethod.POST})
    public AjaxResult summary(HttpServletRequest request, @RequestBody ProjectImplementationSummary projectImplementationSummary){
        try {
            return projectImplementationService.summary(projectImplementationSummary);
        } catch (Exception e) {
            LOGGER.error("ProjectImplementationController team error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 项目实施 - 项目执行
     * 参数说明 ProjectImplementationImplement 数组
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="项目实施 - 项目执行")
    @UBA(module = "调试经营管理", action = "项目执行", channel = OperatorType.Button)
    @RequestMapping(value = "/implement", method = {RequestMethod.POST})
    public AjaxResult implement(HttpServletRequest request, @RequestBody ProjectImplementVo projectImplementVo){
        try {
            List<ProjectImplementationImplement> implementList = projectImplementVo.getImplementList();
            String projectSummaryRequirement = projectImplementVo.getProjectSummaryRequirement();
            return projectImplementationService.implement(implementList, projectSummaryRequirement);
        } catch (Exception e) {
            LOGGER.error("ProjectImplementationController implement error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 项目实施 - 合同收款
     * 参数说明 ProjectImplementationSummaryInfo 数组
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="项目实施 - 合同收款")
    @UBA(module = "调试经营管理", action = "合同收款", channel = OperatorType.Button)
    @RequestMapping(value = "/summaryInfo", method = {RequestMethod.POST})
    public AjaxResult summaryInfo(HttpServletRequest request, @RequestBody List<ProjectImplementationSummaryInfo> summaryInfoList){
        try {
            return projectImplementationService.summaryInfo(summaryInfoList);
        } catch (Exception e) {
            LOGGER.error("ProjectImplementationController summaryInfo error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

}
